package com.xiaoran.robot.customHandler;

import com.xiaoran.robot.entity.SenderInfo;
import com.xiaoran.robot.service.impl.WsCosServiceImpl;
import com.xiaoran.robot.utils.MessageParser;
import com.xiaoran.robot.utils.RstMsgUtils;
import com.xiaoran.robot.utils.SpringUtil;
import com.xiaoran.robot.utils.YamlReader;

import java.util.ArrayList;

public class Cos {
    private final String ws_cosPath = YamlReader.instance.getValueByKey("mirai.cosPath").toString();
    private final WsCosServiceImpl wsCosService = (WsCosServiceImpl) SpringUtil.getBean("wsCosServiceImpl");
    public ArrayList<Object> result(){
        MessageParser instance = MessageParser.getInstance();
        SenderInfo senderInfo = instance.senderInfo();
        String qq = senderInfo.getQid();
        RstMsgUtils rstMsg = new RstMsgUtils();
        if(senderInfo.getType().equals("GroupMessage")){
            rstMsg.atQQ(qq);
        }
        return rstMsg
                .addText("高清cos图来咯")
                .addImageUrl(wsCosService.oneCos()).build();
    }
//    public String getImg(String url){
//        String filePath = ws_cosPath + new SimpleDateFormat("yyyyMMdd").format(new Date())
//                .concat(UUID.randomUUID().toString()).concat(".jpg");
//        try {
//            StopWatch stopWatch = new StopWatch();
//            stopWatch.start("cos");
//            FileUtils.copyURLToFile(new URL(url), new File(filePath));
//            stopWatch.stop();
//            System.out.println("cos图片下载耗时："+stopWatch.getTotalTimeSeconds());
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return filePath;
//    }
}
